home *** CD-ROM | disk | FTP | other *** search
- #include "speech.proto.h"
- #include "maclook.proto.h"
- #include "rsdefs.h"
- #include "rsinterf.proto.h"
- #include <Memory.h>
- #include <Speech.h>
- #include <Windows.h>
-
-
- SpeechChannel gSpeechChannel = nil;
- Handle gSpeechText = nil;
-
-
- static pascal void MySpeechDoneCallback(SpeechChannel channel, Boolean * doneSpeaking)
- {
- *doneSpeaking = true;
- }
-
-
-
- void SpeakSelection(WindowPtr window)
- {
- OSErr err;
-
- do {
- short w;
- Handle speechText;
- Size numberSpeechTextBytes;
-
- if (!gCanSpeak || nil == window) {
- break;
- }
-
- /* convert window to a screen index */
-
- w = RSfindvwind(window);
- if (0 > w) {
- break;
- }
-
- /* get the selected text */
-
- speechText = RSGetTextSel(w, 0);
- if (nil == speechText) {
- break;
- }
-
- /* Stop the old speech channel */
-
- StopSpeaking();
-
- /* Get a speech channel */
-
- gSpeakingVoiceIndex = gSelectedVoiceIndex;
- MoveHHi((Handle)gVoices);
- HLock((Handle)gVoices);
- err = NewSpeechChannel(&(*gVoices)[gSpeakingVoiceIndex], &gSpeechChannel);
- HUnlock((Handle)gVoices);
- if (noErr != err) {
-
- /* The voice that the user selected doesn't work; let's try the rest */
-
- HLock((Handle)gVoices);
- for (gSpeakingVoiceIndex = 0; gSpeakingVoiceIndex < gNumberVoices; gSpeakingVoiceIndex++) {
- err = NewSpeechChannel(&(*gVoices)[gSpeakingVoiceIndex], &gSpeechChannel);
- if (noErr == err) {
- break;
- }
- }
- HUnlock((Handle)gVoices);
- if (gSpeakingVoiceIndex == gNumberVoices) {
- StopSpeaking();
- break;
- }
- }
-
- /* Set up the callback */
-
- err = SetSpeechInfo(gSpeechChannel, soRefCon, &gDoneSpeaking);
- if (noErr != err) {
- StopSpeaking();
- break;
- }
-
- err = SetSpeechInfo(gSpeechChannel, soSpeechDoneCallBack, MySpeechDoneCallback);
- if (noErr != err) {
- StopSpeaking();
- break;
- }
-
- /* Start speaking the new text */
-
- gSpeechText = speechText;
- MoveHHi(gSpeechText);
- HLock(gSpeechText);
- numberSpeechTextBytes = GetHandleSize(gSpeechText);
-
- err = SpeakText(gSpeechChannel, *gSpeechText, numberSpeechTextBytes);
- if (noErr != err) {
- StopSpeaking();
- break;
- }
-
- /* Flash the selection, and fix the menu */
-
- FlashSelection(w);
- AdjustSpeechMenu(true);
-
- } while (false);
-
- if (noErr != err) {
- DoSpeechError(err);
- }
- }
-